error.test.js ➔ describe   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 40
rs 8.8571

1 Function

Rating   Name   Duplication   Size   Complexity  
A error.test.js ➔ ... ➔ describe 0 17 1
1
import chai from 'chai';
2
3
import CodingameError from '../../src/codingame/error.js';
4
5
let expect = chai.expect;
6
7
describe(`[module] codingame/error`, function() {
8
	describe(`[method] constructor`, function() {
9
		it(`should create a default CodingameError with empty message`, function() {
10
			let error = new CodingameError();
11
			expect(error).to.be.an.instanceof(CodingameError).and.has.a.property(`message`).empty;
0 ignored issues
show
introduced by
The result of the property access to expect(error).to.be.an.i...operty(`message`).empty is not used.
Loading history...
12
		});
13
		it(`should create a CodingameError with the specified message`, function() {
14
			let message = `Specified message`;
15
			let error = new CodingameError(message);
16
			expect(error).to.be.an.instanceof(CodingameError).and.has.a.property(`message`, message);
17
		});
18
		it(`should create a CodingameError from an Error`, function() {
19
			let message = `Some error`;
20
			let error = new Error(message);
21
			let cgerror = new CodingameError(error);
22
			expect(cgerror).to.be.an.instanceof(CodingameError).and.has.a.property(`message`, message);
23
		});
24
	});
25
	describe(`[method] metadata`, function() {
26
		it(`should attach metadatas to the CodingameError`, function() {
27
			let value = `42`;
28
			let meta = { "property": value };
29
			let error = new CodingameError();
30
			error.attach(meta);
31
			expect(error).to.have.a.property(`property`, value);
32
		});
33
		it(`should not replace 'name' and 'message' properties`, function() {
34
			let value = 42;
0 ignored issues
show
Unused Code introduced by
The variable value seems to be never used. Consider removing it.
Loading history...
35
			let meta = {
36
				"name": `myname`,
37
				"message": `Not an error message`
38
			};
39
			let message = `Error message`;
40
			let error = new CodingameError(message);
41
			error.attach(meta);
42
			expect(error).to.have.a.property(`name`, `CodingameError`);
43
			expect(error).to.have.a.property(`message`, message);
44
		});
45
	});
46
});
47